using System.Collections;
using UnityEngine;
using UnityEngine.SceneManagement;

public class ButtonBannersContainer : MonoBehaviour
{
	public GameObject Button;

	public GameObject objImage;

	public bool deactivateWhenPromoDisable;

	private bool _dailyCoinsAvailable = true;

	private void Start()
	{
		FyberWrapper.dailyCoinsUnavailable += DailyCoinsUnavailableHandler;
		FyberWrapper.nextVideo += NextVideoEventHandler;
	}

	private void OnDestroy()
	{
		FyberWrapper.dailyCoinsUnavailable -= DailyCoinsUnavailableHandler;
		FyberWrapper.nextVideo += NextVideoEventHandler;
	}

	private void OnEnable()
	{
		if (SceneManager.GetActiveScene().name != "Lobby")
		{
			Button.SetActive(false);
			if (objImage != null)
			{
				objImage.SetActive(false);
			}
		}
		else
		{
			CheckStateButton();
			StartCoroutine(CheckState());
		}
	}

	private void OnDisable()
	{
		StopAllCoroutines();
	}

	private void DailyCoinsUnavailableHandler()
	{
		_dailyCoinsAvailable = false;
	}

	private void NextVideoEventHandler(int reward, string rewardType)
	{
		_dailyCoinsAvailable = true;
	}

	public void ButtonClick()
	{
		ReplacePerelivController.instance.OpenBunnerButton();
	}

	private IEnumerator CheckState()
	{
		while (true)
		{
			yield return new WaitForSeconds(1f);
			CheckStateButton();
		}
	}

	private void CheckStateButton()
	{
		if (ReplacePerelivController.instance != null && (ReplacePerelivController.instance.ShowButton() || (_dailyCoinsAvailable && !deactivateWhenPromoDisable)))
		{
			Button.SetActive(true);
			if (LobbyGold.instance != null)
			{
				LobbyGold.instance.gameObject.SetActive(true);
			}
			if (objImage != null)
			{
				objImage.SetActive(true);
			}
		}
		else
		{
			Button.SetActive(false);
			if (LobbyGold.instance != null)
			{
				LobbyGold.instance.gameObject.SetActive(false);
			}
			if (objImage != null)
			{
				objImage.SetActive(false);
			}
		}
	}
}
